//
//  LLiGveLikeListViewController.m
//  LoveLove
//
//  Created by 达迩科技 on 2019/4/9.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLiGveLikeListViewController.h"
#import "LLNotice1TableViewCell.h"
#import "LLNotice2TableViewCell.h"
#import "LLStatusModel.h"
#import "LLNewsVideoDetialVC.h"
#import "LLNewsImageDetialVC.h"

@interface LLiGveLikeListViewController ()

@property (nonatomic,strong) NSMutableArray *dataArray;



@end

@implementation LLiGveLikeListViewController

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
   
}

#pragma mark - 显示视图操作方法
- (void)configTableView {
    self.needRefresh = NO;
    [super configTableView];
    self.tableView.backgroundColor = LLColorRGB(255);
    self.tableView.mj_h = LLScreenHeight-self.navH-40;
    [self.tableView registerCellByClassName:@"LLNotice1TableViewCell"];
    [self.tableView registerCellByClassName:@"LLNotice2TableViewCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        if (self.type == 0) {
             [self sendDianZanRequst:@"30"];
        }else{
             [self sendDianZanRequst:@"34"];
        }

    }];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        self.page= 1;
        [self.dataArray removeAllObjects];
        if (self.type == 0) {
            [self sendDianZanRequst:@"30"];
        }else{
            [self sendDianZanRequst:@"34"];
        }

    }];
    [self.tableView.mj_header beginRefreshing];
}



#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LLNotice1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LLNotice1TableViewCell"];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//无高亮选中
    cell.backgroundColor = [UIColor whiteColor];
    [cell configNoticeCell:self.dataArray[indexPath.row]];
    if (self.type == 1) {
        cell.praiseButton.hidden = YES;
        cell.lineview.frame = CGRectMake(66, 55, LLScreenWidth-66, 1);
        cell.booknameLabel.frame = CGRectMake(66, 33, LLScreenWidth-81, 13);
    } 
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.type == 0) {
        return 93;
    } else {
        return 56;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0000001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0000001;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    NSDictionary *dict = self.dataArray[indexPath.row];

    LLStatusModel *model = [LLStatusModel new];
    model.newsId = dict[@"id"];
    model.newsTitle = dict[@"new_title"];
    model.type = dict[@"type"];

    if ([model.type intValue] == 1) {

        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        lab.backgroundColor = [UIColor redColor];

        LLNewsVideoDetialVC *vc = [LLNewsVideoDetialVC new];
        vc.model = model;
        vc.titleView = lab;
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([model.type intValue] == 2 ||
             [model.type intValue] == 3 ||
             [model.type intValue] == 4) {

        LLNewsImageDetialVC *vc = [LLNewsImageDetialVC new];
        vc.model = model;
        vc.titleLabel.text = model.newsTitle;
        [self.navigationController pushViewController:vc animated:YES];
    }
}


#pragma mark---点赞
-(void)sendDianZanRequst:(NSString *)code{
    LLUserInfo *user = [LLUserInfo sharedUser];
    
    NSDictionary *dic = @{@"edu_id":code,@"user_random":user.user_random,@"user_id":user.user_id};
    [LLHttpTool post:LLHOST headParams:nil params:dic success:^(NSDictionary *result) {
        self.page++;
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        NSArray *dataArr = result[@"data"][@"result"];
//        self.lab.text = [NSString stringWithFormat:@"一共发布了%ldb篇文章",dataArr.count];
        if (dataArr.count == 0) {
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
            return ;
        }
        [self.dataArray addObjectsFromArray:dataArr];
        [self.tableView reloadData];
    } failure:^(NSString *msg) {
        [SVProgressHUD showErrorWithStatus:msg];
    }];
    
}

@end
